const config = require('../config')
const abi = require('./TokenMessenger');
const {ethers} = require('ethers');
class TokenMessager {
    constructor(url, scAddr){
        this.url = url;
        this.scAddr = scAddr;
        this.provider = new ethers.providers.JsonRpcProvider(url);
        this.scInst = new ethers.Contract(this.scAddr, abi, this.provider);
    }
    async depositForBurn(wallet, amount, destinationDomain, mintRecipient, burnToken) {
        let newWallet = wallet.connect(this.provider);
        let newScInst = this.scInst.connect(newWallet);
        let tx = await newScInst.depositForBurn(amount, destinationDomain, mintRecipient, burnToken);
        let receipt = await tx.wait();
        return receipt;
    }
}


const tokenMessager = new TokenMessager(config.goerli.urls[0], config.goerli.scAddr.ETH_TOKEN_MESSENGER_CONTRACT_ADDRESS);

module.exports = tokenMessager;

/*
* {
  to: '0x0e9B63A28d26180DBf40E8c579af3aBf98aE05C5',
  from: '0x01239Bb69d0C5f795DE5C86Fd00D25F9cD3B9deb',
  contractAddress: null,
  transactionIndex: 0,
  gasUsed: BigNumber { _hex: '0x27c340', _isBigNumber: true },
  blockHash: '0xaadf97f2962b9e9ef0d8ba41f7a10f122bd45dd22b900a24cea4950ad9bc3c38',
  transactionHash: '0x43f17e86f1932de6491b1465bb561150e3a62bef8c9261e6c3622a3e99efd70c',

* */
